package com.zhuannimei.adapter;

import java.util.List;

import org.apache.commons.codec.binary.StringUtils;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhuannimei.R;
import com.zhuannimei.adapter.AppAdapter.ViewHodler;
import com.zhuannimei.domain.ProductUser;
import com.zhuannimei.utility.JackViewHolder;

public class ProductUserAdapter extends BaseObjectListAdapter {

	private LayoutInflater lf;
	private Context context;
	private List<? extends Object> datas;

	public ProductUserAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
		this.context = context;
		this.datas = datas;
		lf = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = lf.inflate(R.layout.item_ranking, null);
		}
		ProductUser cInfo = (ProductUser) datas.get(position);

		TextView userName = JackViewHolder.get(convertView, R.id.username);
		TextView userPoint = JackViewHolder.get(convertView, R.id.userpoint);
		TextView index = JackViewHolder.get(convertView, R.id.index);
		TextView back = JackViewHolder.get(convertView, R.id.rank_back_rl);

		// //
		// WindowManager wm = (WindowManager) context
		// .getSystemService(Context.WINDOW_SERVICE);
		// int width = wm.getDefaultDisplay().getWidth();
		// String snum = ((ProductUser) datas.get(0)).getPoint();
		// int numall = 0;
		// if (TextUtils.isEmpty(snum)) {
		// numall = width;
		// } else {
		// numall = Integer.parseInt(snum);
		// }
		// int numnow = Integer.parseInt(cInfo.getPoint());
		//
		// if (numall != 0) {
		// back.setWidth(width * numnow / numall);
		index.setText(position + 1 + "");
		// if (position < 8) {
		// back.setBackgroundColor(Color.parseColor("#f" + (position + 2)
		// + "" + (position + 2) + "3BD"));
		//
		// } else {
		// back.setBackgroundColor(Color.parseColor("#f" + 9 + "93bd"));
		// }
		userName.setText(cInfo.getUserName());
		userPoint.setText(cInfo.getPoint() + "积分");
		// }
		return convertView;
	}
}
